﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using OnlineManagement.DBUtility;

namespace OnlineManagement.SQLServerDAL
{
   public partial class FaQingRecord:OnlineManagement.IDAL.IFaQingRecord
    {
       /// <summary>
       /// 
       /// </summary>
       /// <param name="record"></param>
       /// <param name="returnValue"></param>
       /// <returns></returns>
        public bool SowFaQingAddOrUpdate(Model.FaQingRecord record, out string returnValue)
        {
            returnValue = "";
            string procName = Common.PubProcedures.SowFaQingRecordAddProce;
            if(record==null){
                returnValue = "";
                return false;
            }
            
            SqlParameter[] parameters = { 
                    new SqlParameter("@hoggeryID", SqlDbType.Int,4),
					new SqlParameter("@sowID", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@faQingDate", SqlDbType.Date,3),
					new SqlParameter("@sowDayOld", SqlDbType.TinyInt,1),
					new SqlParameter("@sowFaQingWeight", SqlDbType.Float,8),
					new SqlParameter("@Comment", SqlDbType.NVarChar,200),

                    new SqlParameter("@rowsAffected",SqlDbType.TinyInt,1),
                    new SqlParameter("@msg",SqlDbType.NVarChar,200)
                                        };
            parameters[0].Value = record.HoggeryId;
            parameters[1].Value = record.SowId;
            parameters[2].Value = record.FaQingDate;
            parameters[3].Value = record.SowDayOld;
            parameters[4].Value = record.SowFaQingWeight;
            parameters[5].Value = record.Comment;
            parameters[6].Direction = ParameterDirection.Output;
            parameters[7].Direction = ParameterDirection.Output;
            int rowsAffected=0;
            try
            {
                DbHelperSQL.RunProcedure(procName, parameters, out rowsAffected, out returnValue);
                return rowsAffected > 0 ? true : false;
            }catch(Exception ex){
                throw new Exception(Common.PubMsg.ServerError);
            }
        }
    }
}
